#
#	Common Makefile
#	Figure out the build flags based on platform guessing
#	by nicknickolaev@gmail.com
#

#Figure out the OS
OS=$(shell uname -s)
MACHINE=$(shell uname -m)

#Linux
ifeq ($(OS), Linux)

#NVidia
ifneq ($(strip $(NV_COMPUTE_SDK_PATH)),  )
OPENCLSDK=$(NV_COMPUTE_SDK_PATH)/OpenCL/common
INC_FLAGS=-I $(OPENCLSDK)/inc
LIB_FLAGS= -lOpenCL -lglut

ifeq ($(MACHINE), x86_64)
LIB_FLAGS+=-L $(OPENCLSDK)/lib/Linux64
else
LIB_FLAGS+=-L $(OPENCLSDK)/lib/Linux32
endif

#ATI
else ifneq ($(strip $(ATISTREAMSDKROOT)),  )
OPENCLSDK=$(ATISTREAMSDKROOT)
INC_FLAGS=-I $(OPENCLSDK)/include
LIB_FLAGS= -lOpenCL -lglut

ifeq ($(MACHINE), x86_64)
LIB_FLAGS+=-L $(OPENCLSDK)/bin/x86_64
else
LIB_FLAGS+=-L $(OPENCLSDK)/bin/x86
endif

else
#No linux OpenCL implementation detected
endif

#Cygwin, Windows
else ifeq ($(OS), CYGWIN_NT-5.1)

#ATI
ifneq ($(strip $(ATISTREAMSDKROOT)),  )
OPENCLSDK=$(ATISTREAMSDKROOT)
INC_FLAGS= -I "$(OPENCLSDK)\include"
#LIB_FLAGS= -Wl,-verbose -Wl,-enable-auto-import -Wl,-enable-extra-pe-debug -Wl,-enable-stdcall-fixup -lOpenCL -lglut32
LIB_FLAGS= -Wl,-enable-stdcall-fixup -lOpenCL -lglut32 "$(OPENCLSDK)\lib\x86\amdrt_x86.o"

ifeq ($(MACHINE), x86_64)
LIB_FLAGS+=-L "$(OPENCLSDK)\lib\x86_64"
else
LIB_FLAGS+=-L "$(OPENCLSDK)\lib\x86"
endif

else
#No linux OpenCL implementation detected
endif

#Darwin, OSX
else ifeq ($(OS), Darwin)
INC_FLAGS=
LIB_FLAGS=-framework OpenGL -framework GLUT -framework Foundation -framework OpenCL -lstdc++
else
#signal not supported
endif
